package cn.itcast.dao.impl;

import cn.itcast.dao.IUserDao;
import cn.itcast.pojo.User;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * *
 * Created by IntelliJ IDEA.
 * Author: caolei
 * Date: 2018/9/9
 * Time: 20:03
 * *
 */
public class UserDaoImpl implements IUserDao {

    private SqlSession sqlSession;

    public UserDaoImpl(SqlSession sqlSession) {
        this.sqlSession = sqlSession;
    }

    public User queryUserById(Long id) {
        User user = sqlSession.selectOne("UserDaoMapper.queryUserById", id);
        return user;
    }

    public List<User> queryUserList() {
        List<User> list = sqlSession.selectList("UserDaoMapper.queryUserList");
        return list;
    }

    public void insertUser(User user) {
        sqlSession.insert("UserDaoMapper.insertUser", user);

    }

    public void updateUser(User user) {
        sqlSession.update("UserDaoMapper.updateUser", user);

    }

    public void deleteUserById(Long id) {
        sqlSession.delete("UserDaoMapper.deleteUserById", id);

    }
}
